Release 10.1A: OpenEdge Development:
ProDataSets
MERGE-CHANGES and MERGE-ROW-CHANGES methods
Once you have passed such a change ProDataSet to the server for update processing, it is quite likely that the ProDataSet data will be further modified on the server. For one thing, database triggers or other server-side code can make changes to the data, such as assigning key values from database sequences, generating values for calculated fields, and so on. In addition, any errors that result from the validation logic or from attempting to write invalid values back to the database will be logged in the
ERROR-STRINGattribute of the temp-tables or their individual records. For this reason, your client-side procedures will most often pass a change ProDataSet as anINPUT-OUTPUTparameter to the server business logic procedure, in order to get the final versions of all the records back, as well as any error messages.Your client-side procedure can then scan the ProDataSet for error messages as it is returned. It then needs to merge any changes into the origin ProDataSet on the client so that the user can see the final versions of records in the user interface. The
MERGE-CHANGESmethod replaces all the after-table values in the origin ProDataSet with the final values in the change ProDataSet.MERGE-CHANGEShas the same syntax as other methods that operate on two ProDataSets, as shown:
MERGE-CHANGESis almost always used in conjunction withGET-CHANGES. The ProDataSet that is theorigin-datasetof theGET-CHANGESmethod must be theorigin-datasetof aMERGE-CHANGESmethod, and thechange-datasetfor theMERGE-CHANGESmethod must be thechange-datasetof theGET-CHANGESmethod that populated it. TheGET-CHANGESmethod sets attribute values that allow a laterMERGE-CHANGESmethod on the same pair of ProDataSets to move changes back into the origin ProDataSet.If you want to merge all after-image table rows whether or not they contain changes, use the optional logical expression,
copy-all-mode, In this case, the temp-table in the original ProDataSet object must have a unique primary index that Progress can use to find each corresponding row from the after-image table (since unchanged rows do not have a corresponding row in the before-image table). When a corresponding row is not found in the original ProDataSet object, Progress creates a new row using the row from the after-image table. WhenFALSE, Progress merges only after-image table rows that contain changes. The default value isFALSE.In some cases, you might need to construct a change ProDataSet yourself that is not the result of a call to
GET-CHANGES, for example, if you need to do specialized processing that is not handled byGET-CHANGES. For this reason, we expose the attributes thatMERGE-CHANGESuses to reconcile the two ProDataSets and allow you to set their values so that you can simulate in your own custom 4GL code everything thatGET-CHANGESdoes for you. These attributes are theORIGIN-HANDLEof each modified temp-table and theORIGIN-ROWIDof each row, and they are explained later in this section.Likewise, you might in some cases need to do your own merge between two ProDataSets instead of using the
MERGE-CHANGESmethod. In this case, if you have a way to identify the corresponding rows reliably between the two ProDataSets, you can do this in your own 4GL code if you need behavior different from whatMERGE-CHANGESdoes for you.
GET-CHANGESstores theRowIDof each before-table row from theorigin-datasetas an attribute of the equivalent row in thechange-dataset, so thatMERGE-CHANGEScan correctly buffer-copy final row values back to the origin ProDataSet. Relying on the primary key or other data in the records would not be reliable in the general case because the key value might have been changed in the business logic. In fact, in the case of a newly created record, it is likely to have been changed because key values are often assigned from database sequences that are available only where the database is connected.The before-table
RowIDattribute is calledORIGIN-ROWID. For each before-table row in thechange-datasetof theMERGE-CHANGESmethod, this attribute holds theRowIDof the corresponding before-table row in theorigin-dataset.Temp-table
RowIDsare, of course, highly transitory. If you create the same set of temp-table rows twice in succession, they will almost always have differentRowIDseach time. To assure insofar as possible that theRowIDssaved as theORIGIN-ROWIDsare still valid,GET-CHANGESalso stores the temp-table handle for the after-table of theorigin-datasetas an attribute calledORIGIN-HANDLEon the equivalent temp-table in thechange-dataset. When you apply theMERGE-CHANGESmethod to two ProDataSets, Progress verifies that theORIGIN-HANDLEs of any modified temp-tables in thechange-dataset(the source ofMERGE-CHANGES) match the temp-table handles in theorigin-dataset. If they do not match, or if anyORIGIN-ROWIDscannot be found in the origin ProDataSet, an error results.If you set these attributes yourself to do your own custom version of what
GET-CHANGESandMERGE-CHANGESdo, you must exercise care to make sure that you identify, set, and use the values properly. InvalidRowIDscould result in very unpredictable and undesirable behavior.There is also a
MERGE-ROW-CHANGESmethod to merge only a single changed row back into theorigin-dataset:
The
change-buffer-handleis the before-table buffer handle in thechange-dataset. Theoriginal-buffer-handleis the corresponding buffer in theorigin-dataset. This argument is optional because Progress can normally determine the handle automatically from the change-table attributes.These methods are normally executed after passing the change ProDataSet to another procedure to process the changes.
MERGE-CHANGESverifies that theORIGIN-HANDLEof each change table matches the object handle of the equivalent table in the original ProDataSet, and returns an error if they don’t match. It finds each before-table record in the original ProDataSet based on theORIGIN-ROWIDattribute of each changed row, and uses that to merge changes back into the original ProDataSet. If there are any mismatches here, this likewise results in an error.MERGE-ROW-CHANGESdoes the same for a single row.When changes are merged, any error flags in the data cause a change to be rejected instead of merged. Otherwise, the change is accepted and the table statuses are updated accordingly. The methods and attributes that control this are described just below and are summarized here with respect to their relation to the
MERGE-CHANGESmethod.If either the
ERRORattribute or theREJECTEDattribute is true for a row, thenMERGE-CHANGESorMERGE-ROW-CHANGESperforms aREJECT-ROW-CHANGESon the row instead of merging it. If theREJECTEDattribute is true for a table, then aMERGE-CHANGESthat is executed on the whole ProDataSet runsREJECT-CHANGESon the table instead of merging it. For each table or row that is merged back into the original ProDataSet, the merge operation does anACCEPT-CHANGESorACCEPT-ROW-CHANGESimplicitly.
|
Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |